Conditions | 1 |
Paths | 1 |
Total Lines | 185 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* jshint -W101, -W098 */ |
||
66 | describe('data api', function() { |
||
67 | it('test address', function(cb) { |
||
68 | client.address("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", function(err, address) { |
||
69 | assert.ifError(err); |
||
70 | assert.ok(address['address']); |
||
71 | assert.equal(address['address'], '3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief'); |
||
72 | |||
73 | // trim off deprecated fields |
||
74 | delete address.category; |
||
75 | delete address.tag; |
||
76 | delete address.first_seen; |
||
77 | delete address.last_seen; |
||
78 | delete address.total_transactions_in; |
||
79 | delete address.total_transactions_out; |
||
80 | delete address.unconfirmed_utxos; |
||
81 | // trim off new fields |
||
82 | delete address.first_tx; |
||
83 | delete address.last_tx; |
||
84 | |||
85 | assert.deepEqual( |
||
86 | address, |
||
87 | require('./test_data/address.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief') |
||
88 | ); |
||
89 | |||
90 | cb(); |
||
91 | }); |
||
92 | }); |
||
93 | it('test addressTransactions', function(cb) { |
||
94 | client.addressTransactions("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", {limit: 20}, function(err, address_txs) { |
||
95 | assert.ifError(err); |
||
96 | |||
97 | assert.ok(address_txs['data']); |
||
98 | assert.ok(address_txs['total']); |
||
99 | |||
100 | var expected = require('./test_data/addressTxs.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief'); |
||
101 | var expectedTxMap = {}; |
||
102 | expected.data.forEach(function(tx) { |
||
103 | cleanTx(tx); |
||
104 | expectedTxMap[tx.hash] = tx; |
||
105 | }); |
||
106 | |||
107 | address_txs.data.forEach(function(tx) { |
||
108 | cleanTx(tx); |
||
109 | assert.deepEqual(tx, expectedTxMap[tx.hash]); |
||
110 | }); |
||
111 | |||
112 | cb(); |
||
113 | }); |
||
114 | }); |
||
115 | it('test addressUnconfirmedTransactions', function(cb) { |
||
116 | client.addressUnconfirmedTransactions("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp", {limit: 23}, function(err, address_txs) { |
||
117 | assert.ifError(err); |
||
118 | assert.ok('data' in address_txs); |
||
119 | assert.ok('total' in address_txs); |
||
120 | assert.ok(address_txs['total'] >= address_txs['data'].length); |
||
121 | |||
122 | cb(); |
||
123 | }); |
||
124 | }); |
||
125 | it('test addressUnspentOutputs', function(cb) { |
||
126 | client.addressUnspentOutputs("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", {limit: 23}, function(err, address_utxo) { |
||
127 | assert.ifError(err); |
||
128 | assert.ok('data' in address_utxo); |
||
129 | assert.ok('total' in address_utxo); |
||
130 | assert.ok(address_utxo['total'] >= address_utxo['data'].length); |
||
131 | |||
132 | cb(); |
||
133 | }); |
||
134 | }); |
||
135 | it('test verifyAddress', function(cb) { |
||
136 | client.verifyAddress("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk=", function(err, result) { |
||
137 | assert.ifError(err); |
||
138 | assert.ok(result); |
||
139 | |||
140 | cb(); |
||
141 | }); |
||
142 | }); |
||
143 | it('test block by hash', function(cb) { |
||
144 | client.block("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", function(err, block) { |
||
145 | assert.ifError(err); |
||
146 | assert.ok(block['hash']); |
||
147 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
148 | |||
149 | var expected = require('./test_data/block.000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
150 | |||
151 | cleanBlock(block); |
||
152 | cleanBlock(expected); |
||
153 | |||
154 | assert.deepEqual(block, expected); |
||
155 | |||
156 | cb(); |
||
157 | }); |
||
158 | }); |
||
159 | it('test block by height', function(cb) { |
||
160 | client.block(200000, function(err, block) { |
||
161 | assert.ifError(err); |
||
162 | assert.ok(block['hash']); |
||
163 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
164 | |||
165 | cb(); |
||
166 | }); |
||
167 | }); |
||
168 | it('test blockTransactions', function(cb) { |
||
169 | client.blockTransactions("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", {limit: 23}, function(err, block_txs) { |
||
170 | assert.ifError(err); |
||
171 | assert.ok(block_txs['data']); |
||
172 | assert.ok(block_txs['total']); |
||
173 | assert.ok(block_txs['data'].length === 23); |
||
174 | |||
175 | cb(); |
||
176 | }); |
||
177 | }); |
||
178 | it('test allBlocks', function(cb) { |
||
179 | client.allBlocks({page: 2, limit: 23, sort_dir: 'asc'}, function(err, blocks) { |
||
180 | assert.ifError(err); |
||
181 | |||
182 | assert.ok(blocks['data']); |
||
183 | assert.ok(blocks['total']); |
||
184 | assert.ok(blocks['data'].length === 23); |
||
185 | |||
186 | cb(); |
||
187 | }); |
||
188 | }); |
||
189 | it('test blockLatest', function(cb) { |
||
190 | client.blockLatest(function(err, block) { |
||
191 | assert.ifError(err); |
||
192 | assert.ok(block['hash']); |
||
193 | |||
194 | cb(); |
||
195 | }); |
||
196 | }); |
||
197 | it('test coinbase transaction', function(cb) { |
||
198 | client.transaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", function(err, tx) { |
||
199 | assert.ifError(err); |
||
200 | assert.equal(tx['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); |
||
201 | assert.equal(tx['enough_fee'], null); |
||
202 | |||
203 | cb(); |
||
204 | }); |
||
205 | }); |
||
206 | it('test tx 95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615', function(cb) { |
||
207 | client.transaction("95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615", function(err, tx) { |
||
208 | assert.ifError(err); |
||
209 | assert.equal(tx['hash'], "95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615"); |
||
210 | |||
211 | var expected = require('./test_data/tx.95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615'); |
||
212 | cleanTx(expected); |
||
213 | cleanTx(tx); |
||
214 | |||
215 | assert.deepEqual(tx, expected); |
||
216 | |||
217 | cb(); |
||
218 | }); |
||
219 | }); |
||
220 | it('test batch transactions', function(cb) { |
||
221 | client.transactions([ |
||
222 | "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1", |
||
223 | "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", |
||
224 | "4bbe6feeb50e47e2de5ef6a9d7378363823611dd07d4a5ea1799da9ae6a21665", |
||
225 | "6c0d3156621051a86b8af3f23dfe211e8a17a01bffe3c2b24cbee65139873c6a", |
||
226 | "356210d6b8143e23d0cf4d0dae0ac686015a13fe3b2b46b1cc43a71a36c73355", |
||
227 | "a40d1eee0cec3d963d8df2870bd642bd3fd07163e864aeb90fa5efe9ea91c998", |
||
228 | "1c7e3c9823baa9bb70b09ed666e8a6b3120b07f84429ed41f05d5504bd58f188", |
||
229 | "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80" |
||
230 | ], function(err, txs) { |
||
231 | assert.ifError(err); |
||
232 | |||
233 | assert.equal(Object.keys(txs['data']).length, 8); |
||
234 | |||
235 | var tx1 = txs['data']["c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"]; |
||
236 | assert.equal(tx1['hash'], "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"); |
||
237 | assert.ok(tx1['confirmations']); |
||
238 | |||
239 | var tx2 = txs['data']["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"]; |
||
240 | assert.equal(tx2['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); |
||
241 | |||
242 | var tx8 = txs['data']["1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"]; |
||
243 | assert.equal(tx8['hash'], "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"); |
||
244 | |||
245 | assert.ok(!txs['data']['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff']); |
||
246 | |||
247 | cb(); |
||
248 | }); |
||
249 | }); |
||
250 | }); |
||
251 | |||
252 |